package com.neusoft.neu.controller;

import com.neusoft.neu.service.impl.MemberServiceImpl;
import com.neusoft.neu24.Result.CommonResult;
import com.neusoft.neu24.dto.GridorDTO;
import com.neusoft.neu24.dto.MemberDTO;
import com.neusoft.neu24.dto.UserLoginDTO;
import com.neusoft.neu24.entity.Gridor;
import com.neusoft.neu24.entity.Member;


import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/member")
public class MemberController {

    @Resource
    private MemberServiceImpl memberService;

    @PostMapping("/login")
    public CommonResult<Member> login(@RequestBody UserLoginDTO userLoginDTO){
        System.out.println(userLoginDTO);
        return memberService.login(userLoginDTO);
    }

    @PostMapping("/loginByPhone")
    public CommonResult<Member> loginWithPhone(@RequestBody UserLoginDTO userLoginDTO) {
        return memberService.loginWithPhone(userLoginDTO);
    }

    @GetMapping("/list")
    public CommonResult<List<MemberDTO>> listAll(){
        return memberService.listAll();
    }

    @GetMapping("/new")
    public CommonResult<Integer> newMember() {
        return memberService.newMember();
    }

    @PostMapping("/switch")
    public CommonResult<Integer> switchMember(Member member) {
        return memberService.switchMember(member);
    }

    @GetMapping("/gridor/list")
    public CommonResult<List<GridorDTO>> getGridors() {
        return memberService.getGridors();
    }

    @PostMapping("/gridor/edit")
    public CommonResult<Integer> editGridor(@RequestBody Gridor gridor) {
        return memberService.editGridor(gridor);
    }

    @PostMapping("/add")
    public CommonResult<Integer> addMember(@RequestBody Member member) {
        return memberService.addMember(member);
    }
}
